// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const db = cloud.database()
  const _ =db.command
  return {
   
    youhuiquan:await db.collection('coupons').where({ _openid:wxContext.OPENID,status:0, dateEnd : _.gt(new Date()),}).count(),
    orders0: await db.collection('orders').where({ _openid:wxContext.OPENID,status:0}).count(),
    orders1: await db.collection('orders').where({ _openid:wxContext.OPENID,status:1}).count(),
    orders2: await db.collection('orders').where({ _openid:wxContext.OPENID,status:2}).count(),
    orders3: await db.collection('orders').where({ _openid:wxContext.OPENID,status:99}).count(),
  }
}